package com.gao.weblog.web.markdown.provider;

import org.commonmark.node.Link;
import org.commonmark.node.Node;
import org.commonmark.renderer.html.AttributeProvider;

import java.util.Map;


public class NofollowLinkAttributeProvider implements AttributeProvider {

    private final static String DOMAIN = "www.xuegao.com";
    @Override
    public void setAttributes(Node node, String s, Map<String, String> attributes) {
        if (node instanceof Link){
            Link linkNode = (Link) node;
            String href = linkNode.getDestination();
            if (!href.contains(DOMAIN)){
                attributes.put("href", "nofollow");
            }
        }
    }
}
